home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / programming / c / objective / examples / manx / gadshow.c < prev    next >
C/C++ Source or Header  |  1978-11-24  |  16KB  |  476 lines

  1. /*
  2. ** $Filename: gadshow.c $
  3. ** $Release : 1.0       $
  4. ** $Revision: 1.281     $
  5. ** $Date    : 21/10/92  $
  6. **
  7. **
  8. ** (C) Copyright 1992 Davide Massarenti
  9. **              All Rights Reserved
  10. **
  11. ** MANX 5.2: cc -ps -wdrunpo -so <name>.c
  12. **           ln -o <name> <name>.o -lOGTglue -lc16
  13. **
  14. */
  15.  
  16. #include <OGT/ObjectiveGadTools.h>
  17.  
  18. #define ARGS_TEMPLATE "FONT/K,SIZE/N,USESCREEN/S"
  19. #define ARGS_FONT       (0)
  20. #define ARGS_SIZE       (1)
  21. #define ARGS_USESCREEN  (2)
  22. #define ARGS_NUMOF      (3)
  23.  
  24. static LONG args[ ARGS_NUMOF ];
  25.  
  26.  
  27. static char Class_MultiWay[] = MULTIWAY_OGT_CLASS;
  28. static char Class_String  [] =   STRING_OGT_CLASS;
  29. static char Class_AslReq  [] =   ASLREQ_OGT_CLASS;
  30. static char Class_Button  [] =   BUTTON_OGT_CLASS;
  31. static char Class_ShowText[] = SHOWTEXT_OGT_CLASS;
  32. static char Class_Menu    [] =     MENU_OGT_CLASS;
  33.  
  34.  
  35. struct TextAttr  MyAttr = { NULL, 8 };
  36. struct TextFont *MyFont;
  37.  
  38. struct Screen           *Scr;
  39. APTR                     VInfo;
  40. struct Window           *Win;
  41. Object                 **Gads;
  42. struct RDArgs           *Ra;
  43. struct Hook              StringHook;
  44.  
  45.  
  46. struct TagItem WindowDescTags[] =
  47. {
  48.    { OVI_GimmeZeroZero    , TRUE                                                     },
  49.    { OVI_AdaptWidthToFont , TRUE                                                     },
  50.    { OVI_AdaptHeightToFont, TRUE                                                     },
  51.  
  52.    { OGT_ScaleLeft        , OGT_DomainRelative                                       },
  53.    { OGT_ScaleTop         , OGT_DomainRelative                                       },
  54.    { OGT_ScaleWidth       , OGT_DomainRelative                                       },
  55.    { OGT_ScaleHeight      , OGT_DomainRelative                                       },
  56.    { OGT_DomainXscale     , ~0                                                       },
  57.    { OGT_DomainYscale     , ~0                                                       },
  58.  
  59.    { WA_Activate          , TRUE                                                     },
  60.    { WA_SimpleRefresh     , TRUE                                                     },
  61.    { WA_NoCareRefresh     , TRUE                                                     },
  62.    { WA_DepthGadget       , TRUE                                                     },
  63.    { WA_SizeGadget        , TRUE                                                     },
  64.    { WA_SizeBBottom       , TRUE                                                     },
  65.    { WA_SizeBRight        , TRUE                                                     },
  66.    { WA_DragBar           , TRUE                                                     },
  67.    { WA_Left              , 400                                                      },
  68.    { WA_Top               , 150                                                      },
  69.    { WA_InnerWidth        , 306                                                      },
  70.    { WA_InnerHeight       , 120                                                      },
  71.    { WA_MaxWidth          , -1                                                       },
  72.    { WA_MaxHeight         , -1                                                       },
  73.    { WA_IDCMP             , IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE | IDCMP_VANILLAKEY },
  74.    { WA_CloseGadget       , TRUE                                                     },
  75.    { WA_MenuHelp          , TRUE                                                     },
  76.    { WA_Title             , "GadShow2"                                               },
  77.  
  78.    { TAG_DONE                                                                        },
  79. };
  80.  
  81.  
  82. STRPTR Object1Labels[] =
  83. {
  84.    "Prova_1",
  85.    "Prova_2",
  86.    "Pe_nultimo",
  87.    "_Ultimo",
  88.    NULL
  89. };
  90.  
  91. struct TagItem Object1Desc[] = /* MULTIWAY_OGT_CLASS */
  92. {
  93.    { GA_ID            , 1                },
  94.    { GA_Disabled      , TRUE             },
  95.  
  96.    { OGT_ScaleLeft    , OGT_FontRelative },
  97.    { OGT_ScaleTop     , OGT_FontRelative },
  98.    { OGT_ScaleWidth   , OGT_FontRelative },
  99.    { OGT_ScaleHeight  , OGT_FontRelative },
  100.    { GA_Left          , 80               },
  101.    { GA_Top           , 12               },
  102.  
  103.    { GA_Text          , "Prova"          },
  104.    { OGT_TextPlacement, OGT_Text_LEFT    },
  105.  
  106.    { OGTMW_Labels     , Object1Labels    },
  107.    { OGTMW_ActiveLabel, 1                },
  108.  
  109.    { TAG_DONE                            },
  110. };
  111.  
  112. struct TagItem Object2Desc[] = /* STRING_OGT_CLASS */
  113. {
  114.    { GA_ID            , 2                           },
  115.    { GA_RelVerify     , TRUE                        },
  116.  
  117.    { OGT_SetPosHandle , (OGT_X_Left | OGT_Y_Bottom) },
  118.    { GA_Left          , 2                           },
  119.    { GA_RelBottom     , -1                          },
  120.    { GA_Width         , 70                          },
  121.    { GA_Height        , 12                          },
  122.  
  123.    { GA_Text          , "Ri_tmo"                    },
  124.    { OGT_TextPlacement, OGT_Text_RIGHT              },
  125.  
  126.    { STRINGA_MaxChars , 16                          },
  127.    { STRINGA_TextVal  , "primo"                     },
  128.    { STRINGA_ExitHelp , TRUE                        },
  129.    { STRINGA_EditHook , &StringHook                 },
  130.    { GA_TabCycle      , TRUE                        },
  131.  
  132.    { TAG_DONE                                       },
  133. };
  134.  
  135. struct TagItem Object3Desc[] = /* STRING_OGT_CLASS */
  136. {
  137.    { GA_ID           , 3                            },
  138.    { GA_RelVerify    , TRUE                         },
  139.    { OGT_AppGadget   , TRUE                         },
  140.  
  141.    { OGT_SetPosHandle, (OGT_X_Right | OGT_Y_Bottom) },
  142.    { GA_RelRight     , -1                           },
  143.    { GA_RelBottom    , -1                           },
  144.    { GA_Width        , 70                           },
  145.    { GA_Height       , 12                           },
  146.  
  147.    { GA_Text         , "Ch_ip"                      },
  148.  
  149.    { STRINGA_MaxChars, 16                           },
  150.    { STRINGA_TextVal , "secondo"                    },
  151.    { STRINGA_ExitHelp, TRUE                         },
  152.    { GA_TabCycle     , TRUE                         },
  153.  
  154.    { TAG_DONE                                       },
  155. };
  156.  
  157. struct TagItem Object4Desc[] = /* ASLREQ_OGT_CLASS */
  158. {
  159.    { GA_ID             , 4               },
  160.    { GA_RelVerify      , TRUE            },
  161.  
  162.    { OGT_SetPosHandle  , OGT_X_Right     },
  163.    { GA_RelRight       , -1              },
  164.    { GA_Top            , 1               },
  165.    { GA_Width          , 132             },
  166.    { GA_Height         , 14              },
  167.  
  168.    { GA_Text           , "Fon_t"         },
  169.    { OGT_TextPlacement , OGT_Text_LEFT   },
  170.  
  171.    { OGTAR_Type        , ASL_FontRequest },
  172.    { OGTAR_ShowSelected, TRUE            },
  173.  
  174.    { TAG_DONE                            },
  175. };
  176.  
  177. struct TagItem Object5Desc[] = /* ASLREQ_OGT_CLASS */
  178. {
  179.    { GA_ID             , 5               },
  180.    { GA_RelVerify      , TRUE            },
  181.  
  182.    { OGT_SetPosHandle  , OGT_X_Right     },
  183.    { GA_RelRight       , -1              },
  184.    { GA_Top            , 17              },
  185.    { GA_Width          , 132             },
  186.    { GA_Height         , 14              },
  187.  
  188.    { GA_Text           , "_File"         },
  189.    { OGT_TextPlacement , OGT_Text_LEFT   },
  190.  
  191.    { OGTAR_Type        , ASL_FileRequest },
  192.    { OGTAR_ShowSelected, TRUE            },
  193.  
  194.    { TAG_DONE                            },
  195. };
  196.  
  197. struct TagItem Object6Desc[] = /* ASLREQ_OGT_CLASS */
  198. {
  199.    { GA_ID             , 6                },
  200.    { GA_RelVerify      , TRUE             },
  201.  
  202.    { OGT_SetPosHandle  , OGT_X_Right      },
  203.    { GA_RelRight       , -1               },
  204.    { GA_Top            , 33               },
  205.    { GA_Width          , 132              },
  206.    { GA_Height         , 14               },
  207.  
  208.    { GA_Text           , "_Dir"           },
  209.    { OGT_TextPlacement , OGT_Text_LEFT    },
  210.  
  211.    { OGTAR_Type        , ASL_FileRequest  },
  212.    { ASL_FuncFlags     , FILF_MULTISELECT },
  213.  
  214.    { TAG_DONE                             },
  215. };
  216.  
  217. struct TagItem Object7Desc[] = /* SHOWTEXT_OGT_CLASS */
  218. {
  219.    { GA_ID             , 7                                            },
  220.  
  221.    { OGT_SetPosHandle  , OGT_X_Right                                  },
  222.    { GA_RelRight       , -1                                           },
  223.    { GA_Top            , 49                                           },
  224.    { GA_Width          , 132                                          },
  225.    { GA_Height         , 25                                           },
  226.  
  227.    { GA_Text           , "Text"                                       },
  228.    { OGT_TextPlacement , OGT_Text_LEFT                                },
  229.    { OGT_DrawFrame     , TRUE                                         },
  230.  
  231.    { OGTST_Format      , "\001\002Prova\n\002Di\n\003Piu'\n\004Righe" },
  232.  
  233.    { TAG_DONE                                                         },
  234. };
  235.  
  236. struct TagItem Object8Desc[] = /* MENU_OGT_CLASS */
  237. {
  238.    { OGTMN_Menu         , "Primo"               },
  239.    { OGTMN_Item         , "Primo Primo"         },
  240.    { OGTMN_ShortCut     , 'P'                   },
  241.    { OGTMN_Item         , "Primo Secondo"       },
  242.    { GA_Selected        , TRUE                  },
  243.    { OGTMN_BarLabel                             },
  244.    { OGTMN_Item         , "Primo Terzo"         },
  245.    { OGTMN_ShortCut     , 'T'                   },
  246.    { OGTMN_SubItem      , "Primo Terzo Primo"   },
  247.    { OGTMN_MutualExclude, ~1                    },
  248.    { GA_Selected        , TRUE                  },
  249.    { OGTMN_SubItem      , "Primo Terzo Secondo" },
  250.    { OGTMN_MutualExclude, ~2                    },
  251.    { GA_Selected        , FALSE                 },
  252.    { OGTMN_Menu         , "Secondo"             },
  253.    { OGTMN_Item         , "Secondo Primo"       },
  254.    { OGTMN_Menu         , "Terzo"               },
  255.    { OGTMN_Item         , "Terzo Primo"         },
  256.  
  257.    { TAG_DONE                                   },
  258. };
  259.  
  260.  
  261. struct OGT_ObjectSettings ListOfObjects[] =
  262. {
  263.    { Class_MultiWay, Object1Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  264.    { Class_String  , Object2Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  265.    { Class_String  , Object3Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  266.    { Class_AslReq  , Object4Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  267.    { Class_AslReq  , Object5Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  268.    { Class_AslReq  , Object6Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  269.    { Class_ShowText, Object7Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  270.    { Class_Menu    , Object8Desc, NULL, OGT_NOOBJECT, OGT_NOOBJECT },
  271.    { NULL                                                          },
  272. };
  273.  
  274. struct OGT_ObjectLink ListOfLinks[] =
  275. {
  276.    { OGT_NOOBJECT },
  277. };
  278.  
  279. static void cleanup           ( char *str );
  280. static void goHandleWindowWait( void      );
  281. static BOOL goHandleWindow    ( void      );
  282.  
  283. static ULONG StringEdit( struct Hook   *hook ,
  284.                          struct SGWork *sgw  ,
  285.                          ULONG         *msg  )
  286. {
  287.    ULONG  ret_val = ~0;
  288.  
  289.    switch( *msg )
  290.    {
  291.       case SGH_KEY:
  292.          switch( sgw->EditOp )
  293.          {
  294.             case EO_REPLACECHAR:
  295.             case EO_INSERTCHAR :
  296.                if(!isxdigit( sgw->Code ))
  297.                {
  298.                   sgw->Actions |=  SGA_BEEP;
  299.                   sgw->Actions &= ~SGA_USE;
  300.                }
  301.                else
  302.                {
  303.                   sgw->WorkBuffer[ sgw->BufferPos - 1 ] = ToUpper( sgw->Code );
  304.                }
  305.                break;
  306.          }
  307.          break;
  308.  
  309.       case SGH_CLICK:
  310.          if(sgw->BufferPos < sgw->NumChars)
  311.          {
  312.             sgw->WorkBuffer[ sgw->BufferPos ] = '0';
  313.          }
  314.          break;
  315.  
  316.       default:
  317.          ret_val = 0;
  318.          break;
  319.    }
  320.  
  321.    return( ret_val );
  322. }
  323.  
  324. void main( void )
  325. {
  326.    if(!OpenOGT()) cleanup( "no objectivegadtools library\n" );
  327.  
  328.    if(!(Ra = ReadArgs( ARGS_TEMPLATE, args, NULL ))) cleanup( "can't parse args\n" );
  329.  
  330.    if(args[ ARGS_FONT ]) MyAttr.ta_Name  =  (void  *)args[ ARGS_FONT ];
  331.    if(args[ ARGS_SIZE ]) MyAttr.ta_YSize = *(ULONG *)args[ ARGS_SIZE ];
  332.  
  333.    if(MyAttr.ta_Name)
  334.    {
  335.       if(!(MyFont = OpenDiskFont( &MyAttr ))) cleanup( "can't open font!!\n" );
  336.    }
  337.  
  338.    StringHook.h_Entry    = hookEntry;
  339.    StringHook.h_SubEntry = StringEdit;
  340.  
  341.    while(1)
  342.    {
  343.       if(args[ ARGS_USESCREEN ])
  344.       {
  345.          static UWORD pens[] = { ~0 };
  346.  
  347.          Scr = OpenScreenTags( NULL, SA_Width    , (ULONG)STDSCREENWIDTH ,
  348.                                      SA_Height   , (ULONG)STDSCREENHEIGHT,
  349.                                      SA_Depth    , (ULONG)2              ,
  350.                                      SA_Pens     , (ULONG)pens           ,
  351.                                      SA_Type     , (ULONG)CUSTOMSCREEN   ,
  352.                                      SA_DisplayID, (ULONG)HIRESLACE_KEY  ,
  353.                                      SA_SysFont  , (ULONG)1              ,
  354.                                      TAG_DONE                            );
  355.  
  356.          if(Scr == NULL) cleanup( "can't open my screen.\n" );
  357.       }
  358.  
  359.  
  360.       VInfo = OGT_GetVisualInfo( NULL,       OGT_TextFont                , (ULONG)MyFont         ,
  361.                                        Scr ? WA_CustomScreen : TAG_IGNORE, (ULONG)Scr            ,
  362.                                                                TAG_MORE  , (ULONG)WindowDescTags );
  363.  
  364.       if(VInfo == NULL) cleanup( "can't open my window.\n" );
  365.  
  366.       if(!OGT_BuildObjects( VInfo, ListOfObjects, ListOfLinks, &Gads )) cleanup( "can't create objects" );
  367.  
  368.       Win = OGT_GetWindowPtr( VInfo );
  369.  
  370.       goHandleWindowWait();
  371.  
  372.       SetGadgetAttrs( Gads[ 7 ], Win, NULL, OGTMN_Menu   , (ULONG)"Secondo"      ,
  373.                                             OGTMN_Item   , (ULONG)"Secondo Primo",
  374.                                             OGTMN_NewName, (ULONG)"Second"       ,
  375.                                             TAG_DONE                             );
  376.  
  377.       DisposeObject( Gads[ 0 ] ); Gads[ 0 ] = NULL;
  378.  
  379.       goHandleWindowWait();
  380.  
  381.       Gads[ 0 ] = (APTR)NewObject( NULL, Class_MultiWay, OGT_VisualInfo, (ULONG)VInfo       ,
  382.                                                          TAG_MORE      , (ULONG)Object1Desc );
  383.  
  384.       OGT_RefreshWindow( VInfo );
  385.  
  386.       goHandleWindowWait();
  387.  
  388.       SetGadgetAttrs( Gads[ 0 ], Win, NULL, OGTMW_ActiveLabel, (ULONG)3,
  389.                                             TAG_DONE                   );
  390.  
  391.       SetGadgetAttrs( Gads[ 7 ], Win, NULL, OGTMN_Menu      , (ULONG)"Secondo"       ,
  392.                                             OGTMN_ClearMenus, (ULONG)TRUE            ,
  393.                                             OGTMN_Menu      , (ULONG)"Terzo"         ,
  394.                                             OGTMN_ClearMenus, (ULONG)FALSE           ,
  395.                                             OGTMN_Menu      , (ULONG)"Quarto"        ,
  396.                                             OGTMN_Item      , (ULONG)"Quarto Primo"  ,
  397.                                             OGTMN_Item      , (ULONG)"Quarto Secondo",
  398.                                             GA_Disabled     , (ULONG)TRUE            ,
  399.                                             TAG_DONE                                 );
  400.  
  401.       goHandleWindowWait();
  402.  
  403.       {
  404.          int i;
  405.  
  406.          for(i = 0;i < 8;i++) SetGadgetAttrs( Gads[ i ], Win, NULL, GA_Disabled, (ULONG)TRUE, TAG_DONE );
  407.  
  408.          goHandleWindowWait();
  409.       }
  410.  
  411.       {
  412.          int i;
  413.  
  414.          for(i = 0;i < 8;i++) SetGadgetAttrs( Gads[ i ], Win, NULL, GA_Disabled, (ULONG)FALSE, TAG_DONE );
  415.  
  416.          goHandleWindowWait();
  417.       }
  418.  
  419.       break;
  420.    }
  421.  
  422.    cleanup( "all done" );
  423. }
  424.  
  425. static void cleanup( char *str )
  426. {
  427.    if(str) Printf( "%s\n", str );
  428.  
  429.    if(Ra    ) FreeArgs          ( Ra     );
  430.    if(Gads  ) FreeVec           ( Gads   );
  431.    if(VInfo ) OGT_FreeVisualInfo( VInfo  );
  432.    if(Scr   ) CloseScreen       ( Scr    );
  433.    if(MyFont) CloseFont         ( MyFont );
  434.  
  435.    CloseOGT();
  436.  
  437.    Exit( 0 );
  438. }
  439.  
  440. static void goHandleWindowWait( void )
  441. {
  442.    BOOL keeprunning = TRUE;
  443.  
  444.    while(keeprunning)
  445.    {
  446.       Wait( 1L << Win->UserPort->mp_SigBit );
  447.  
  448.       keeprunning = goHandleWindow();
  449.    }
  450. }
  451.  
  452. static BOOL goHandleWindow( void )
  453. {
  454.    BOOL                 keeprunning = TRUE;
  455.  
  456.    struct IntuiMessage *imsg;
  457.  
  458.    while(keeprunning && (imsg = OGT_GetMsg( VInfo )))
  459.    {
  460.       switch(imsg->Class)
  461.       {
  462.          case IDCMP_CLOSEWINDOW:
  463.             keeprunning = FALSE;
  464.             break;
  465.  
  466.          case IDCMP_VANILLAKEY:
  467.             Printf( "Vanilla Key: %04x %04x\n", imsg->Code, imsg->Qualifier );
  468.             break;
  469.       }
  470.  
  471.       OGT_ReplyMsg( imsg );
  472.    }
  473.  
  474.    return( keeprunning );
  475. }
  476.